package com.ku.user.controller;

import com.ku.user.client.OrderApiClient;
import com.ku.user.common.RedisUtils;
import com.ku.user.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("api/user")
@Slf4j
@Api(tags = "用户管理")
public class UserController {

    @Resource
    private OrderApiClient orderApiClient;
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private HttpServletRequest request;
    @ApiOperation(value = "用户服务检测")
    @GetMapping("index")
    public  String index(){
        String token = request.getHeader("token");
        return "User Service";
    }

    @ApiOperation(value = "用户->订单服务检测")
    @GetMapping("index/order")
    public String indexOrder(){
        String token = request.getHeader("token");
        String orderStr = orderApiClient.index();
        log.info("调用订单服务返回结果==》{}",orderStr);
        return orderStr;
    }

    @PostMapping("login")
    @ApiOperation(value = "用户登录")
    public Result login(){
        String token ="e6053e4c-3140-4713-a1b6-8a76c93e4274";
        redisUtils.set(token,"12312312");
        return Result.success(token);
    }
}
